package com.uprr.netcontrol.starmap.rest.processor;

import java.io.Reader;

import javax.xml.bind.JAXBException;



import com.up.www.schemas.netcontrol.common.starmap.nc_du_deployment_descriptor_1_0.DeploymentUnit;
import com.uprr.netcontrol.starmap.dto.DeploymentUnitDTO;
import com.uprr.netcontrol.starmap.rest.converter.DeploymentUnitDtoConverter;
import com.uprr.netcontrol.starmap.rest.converter.RequestConverter;

public class DefaultDataProcessor implements DataProcessor {

  @Override
   public final DeploymentUnitDTO convertAndProcess(final Reader reader) {
    DeploymentUnitDTO rootDto = null;
    try {
      DeploymentUnit rootSchemaType = RequestConverter.convert(reader);
      rootDto = DeploymentUnitDtoConverter.convert(rootSchemaType);
    } catch (JAXBException e) {
      throw new RuntimeException("Invalid Data XML" + e);
    } catch (Exception e) {
      throw new RuntimeException("Invalid Data XML" + e);
    
    }
    return rootDto;

  }

  @Override
   public final DeploymentUnitDTO process(final DeploymentUnit rootSchemaType) {
    DeploymentUnitDTO rootDto = null;
    try {
      rootDto = DeploymentUnitDtoConverter.convert(rootSchemaType);
    } catch (Exception e) {
      throw new RuntimeException("Invalid Data XML" + e);
    }

    return rootDto;

  }

}
